package cn.edu.szpt.qqdemov3.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.szpt.qqdemov3.R;
import cn.edu.szpt.qqdemov3.beans.QQPluginBean;

public class QQPluginAdapter extends RecyclerView.Adapter<QQPluginAdapter.ViewHolder> {
    private Context context;
    private List<QQPluginBean> data;

    public QQPluginAdapter(Context context, List<QQPluginBean> data) {
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewHolder viewHolder =null;
        View view = LayoutInflater.from(context).inflate(R.layout.item_qqplugin,parent,false);
        viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        QQPluginBean bean = data.get(position);
        holder.tv_companyname.setText(bean.getCompany_name());
        holder.img_softicon.setImageResource(bean.getSoft_icon());
        holder.tv_softname.setText(bean.getSoft_name());
        holder.img_softstar.setImageResource(bean.getSoft_star());
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv_companyname;
        ImageView img_softicon;
        TextView tv_softname;
        ImageView img_softstar;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_companyname = itemView.findViewById(R.id.tv_companyname);
            img_softicon = itemView.findViewById(R.id.img_softicon);
            tv_softname = itemView.findViewById(R.id.tv_softname);
            img_softstar = itemView.findViewById(R.id.img_softstar);
        }
    }
}
